<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="bean.*" %>
<%@ page import="dao.*" %>

<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8"/>
	<script type="text/javascript">
		function del() {
			if(!confirm("确认要删除该名人员相关信息？")) {
				window.event.returnValue = false;
			}
		}
	</script>
	<title>管理界面</title>
	<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
	<link type="text/css" rel="stylesheet" href="css/index.css">
<body>
<%
	Customer c = (Customer) request.getSession().getAttribute("admin");
	if(c == null){
		response.sendRedirect("Not_Login.jsp");
	}
%>
<div class="main">
	<div class="navigation">
				<span>欢迎回来!
					<%
						if(c != null){
							out.print(c.getName());
						}
					%>
					管理员
				</span>
		<a class="exit" href="index.jsp"><span>退出登录</span></a>
	</div>
	<table class="table" style="margin:0 auto;width:90%">
		<tr>
			<td style="width:20%"><button class= "btn btn-info" style="width:100%" onclick="window.location.href='index_Admin.jsp'">公告</button>	</td>
			<td style="width:20%"><button class= "btn btn-info" style="width:100%" onclick="window.location.href='Manage_Students.jsp?pages=1'">学生管理</button></td>
			<td style="width:20%"><button class= "btn btn-info" style="width:100%" onclick="window.location.href='Manage_Teachers.jsp'">教师管理</button></td>
		</tr>
	</table>
	<div>
		<%
			request.setCharacterEncoding("UTF-8");
			String search = request.getParameter("check");
			Customer customer;
			if(search.matches("[0-9]+")){
				customer = AdminSql.getCustomerByID(search);
			}
			else{
				customer = AdminSql.getCustomerByName(search);
			}
		%>
		<table class="table table-hover; table_center"  style="margin:0 auto;width: 90%;color: white;font-weight: bolder">
			<tr>
				<th>编号</th>
				<th>姓名</th>
				<th>密码</th>
				<th>性别</th>
				<th><button class="btn btn-default btn-sm" onclick="window.location.href='Insert_Customer.jsp'">添加人员</button></th>
				<th>
					<form action="Select_Customer.jsp" method="post" >
						<input type="text" name="check" placeholder="请输入查询ID或姓名" style="color: black"/>
						<button class="btn btn-default btn-sm" type="submit" name="submit" >搜索</button>
					</form>
				</th>
			</tr>
			<%
				if (customer!=null){
			%>
			<tr>
				<td><%=customer.getId() %></td>
				<td><%=customer.getName() %></td>
				<td><%=customer.getPassword() %></td>
				<td><%=customer.getSex() %></td>
				<td><button class= "btn btn-default btn-sm" ><a href="Alter_Customer.jsp?ID=<%=customer.getId() %>">修改</a></button></td>
				<td><button class= "btn btn-default btn-sm" onclick='return del();'><a href="RemoveServlet?ID=<%=customer.getId() %>">删除</a></button></td>
			</tr>
			<%
				}
			%>
		</table>
	</div>
</div>

</body>
</html>

